{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-14T09:26:47.006170Z",
     "start_time": "2021-11-14T09:26:25.539641Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎登录tb购物系统\n",
      "请输入您的账号：zhanghan\n",
      "请输入您的密码：7749\n",
      "欢迎 zhanghan 来到tb购物\n",
      "---------【STORE】---------\n",
      "    ['编号', '购物列表', '价格']\n",
      "    ['01', '   洗衣机', 688]\n",
      "    ['02', '   电饭煲', 288]\n",
      "    ['03', '   电冰箱', 999]\n",
      "    ['04', '   电视机', 4999]\n",
      "    \n",
      "您的余额还有：99999999\n",
      "---------【STORE】---------\n",
      "    ['编号', '购物列表', '价格']\n",
      "    ['01', '   洗衣机', 688]\n",
      "    ['02', '   电饭煲', 288]\n",
      "    ['03', '   电冰箱', 999]\n",
      "    ['04', '   电视机', 4999]\n",
      "    \n",
      "请输入您想要购买的物品编号(亦输入“q”退出购买)：1\n",
      "   洗衣机 已经添加到您的购物车，您的余额还有 99999311 元\n",
      "---------【STORE】---------\n",
      "    ['编号', '购物列表', '价格']\n",
      "    ['01', '   洗衣机', 688]\n",
      "    ['02', '   电饭煲', 288]\n",
      "    ['03', '   电冰箱', 999]\n",
      "    ['04', '   电视机', 4999]\n",
      "    \n",
      "请输入您想要购买的物品编号(亦输入“q”退出购买)：2\n",
      "   电饭煲 已经添加到您的购物车，您的余额还有 99999023 元\n",
      "---------【STORE】---------\n",
      "    ['编号', '购物列表', '价格']\n",
      "    ['01', '   洗衣机', 688]\n",
      "    ['02', '   电饭煲', 288]\n",
      "    ['03', '   电冰箱', 999]\n",
      "    ['04', '   电视机', 4999]\n",
      "    \n",
      "请输入您想要购买的物品编号(亦输入“q”退出购买)：q\n",
      "----------------- \n",
      " 您的购物车已放入：[['01', '   洗衣机', 688], ['02', '   电饭煲', 288]]  \n",
      " 您的余额还有：99999023 元\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(\"欢迎登录tb购物系统\")\n",
    "user_id = [\"zhanghan\"]\n",
    "password_id = [\"7749\"]\n",
    "\n",
    "username = input(\"请输入您的账号：\")\n",
    "password = input(\"请输入您的密码：\")\n",
    "\n",
    "if username in user_id:\n",
    "    if password in password_id:\n",
    "        print(\"欢迎\", username, \"来到tb购物\")\n",
    "    else:\n",
    "        print(\"请确认账号密码是否正确\")\n",
    "\n",
    "\n",
    "    goods_list = [\n",
    "        \n",
    "        [\"编号\", \"购物列表\", \"价格\"],\n",
    "        [\"01\", \"   洗衣机\", 688],\n",
    "        [\"02\", \"   电饭煲\", 288],\n",
    "        [\"03\", \"   电冰箱\", 999],\n",
    "        [\"04\", \"   电视机\", 4999],\n",
    "    ]\n",
    "\n",
    "    info = '''---------【STORE】---------\n",
    "    %s\n",
    "    %s\n",
    "    %s\n",
    "    %s\n",
    "    %s\n",
    "    ''' % (goods_list[0], goods_list[1], goods_list[2], goods_list[3], goods_list[4])\n",
    "    print(info)\n",
    "\n",
    "    user_shopping_car = [] \n",
    "\n",
    "    Alipay = int(input(\"您的余额还有：\"))\n",
    "\n",
    "    while True:\n",
    "        print(info)\n",
    "        choice = input(\"请输入您想要购买的物品编号(亦输入“q”退出购买)：\") \n",
    "        if choice.isdigit():\n",
    "            \n",
    "            choice = int(choice)\n",
    "            \n",
    "            if choice < len(goods_list):  \n",
    "                \n",
    "                if Alipay < goods_list[choice][2]:\n",
    "                    \n",
    "                    print(\"您的余额不够，请更换支付方式\")\n",
    "                    \n",
    "                else:\n",
    "                    Alipay = Alipay - int(goods_list[choice][2])\n",
    "                    user_shopping_car.append(goods_list[choice])\n",
    "                    print(goods_list[choice][1], \"已经添加到您的购物车，您的余额还有\", Alipay, \"元\")\n",
    "        \n",
    "            else:\n",
    "                print(\"您输入的商品不存在，请输入正确的编号\")\n",
    "        elif choice == \"q\":\n",
    "            print(\"-----------------\", '\\n', \"您的购物车已放入：%s \" % (user_shopping_car), '\\n', \"您的余额还有：%d 元\" % (Alipay))\n",
    "            break\n",
    "           \n",
    "        else:\n",
    "            print(\"请输入正确的商品编号！！或者输入“q”退出\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
